package com.njsf.conponent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.internet.MimeMessage;

@Component
public class MailUtil {

    @Autowired
    private JavaMailSenderImpl javaMailSender;

    /**
     * @param to 收件人邮箱
     * @param activeCode 激活码
     */
    public void sendMailForRegisterUser(String to,String activeCode) throws Exception{
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,false,"UTF-8");
        helper.setFrom(javaMailSender.getUsername());
        helper.setTo(to);
        helper.setSubject("在线书城用户激活");

        String content = "<a href='http://localhost:80/ssmmavendemo_war_exploded/front/activeuser?activeCode="+activeCode+"'>点击，激活账户</a>";
        helper.setText(content,true);
        javaMailSender.send(mimeMessage);
    }

}
